<?php

namespace App\Support;

class Util
{
    /**
     * 判断是否为时间，格式2001-01-01
     * @param $date
     * @return bool
     */
    public static function isDate($date): bool
    {
        if (!strlen($date)) {
            return false;
        }
        if (10 != mb_strlen($date)) {
            return false;
        }
        return date('Y-m-d', strtotime($date)) === $date;
    }

    /**
     * 获取客户端ip地址
     * @return string
     */
    public static function getClientIp(): string
    {
        $cip = '0.0.0.0';
        if ($_SERVER['REMOTE_ADDR'] ?? '') {
            $cip = $_SERVER['REMOTE_ADDR'];
        } elseif (getenv('REMOTE_ADDR', '')) {
            $cip = getenv('REMOTE_ADDR');
        }

        return (string)$cip;
    }
}
